﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

namespace Mantenimiento.CAD
{
    public class Vehiculo
    {
        public static DataTable buscar()
        {
            dbManager db = new dbManager();

            //PARAMETROS 
            object[] parametros = new object[0];
            DataTable dt = db.EjecutarSP_DS("VEHICULOS_SELECT_ALL", parametros).Tables[0];
            return dt;
        }
        public static DataTable buscar(string sMatricula)
        {
            dbManager db = new dbManager();

            //PARAMETROS 
            object[] parametros = new object[2];
            parametros[0] = "@Matricula";
            parametros[1] = sMatricula;
            DataTable dt = db.EjecutarSP_DS("VEHICULOS_SELECT", parametros).Tables[0];
            return dt;
        }

        public static int insertar
            (string sMatricula, int idModelo, int idExplotacion, int iKilometros, int iHoras, bool bControlPorHoras, DateTime fecha)
        {
            int iRet = -1;

            object[] parametros = new object[14];
            parametros[0] = "@Matricula";
            parametros[1] = sMatricula;
            parametros[2] = "@IdModelo";
            parametros[3] = idModelo;
            parametros[4] = "@IdExplotacion";
            parametros[5] = idExplotacion;
            parametros[6] = "@Kilometros";
            parametros[7] = iKilometros;
            parametros[8] = "@Horas";
            parametros[9] = iHoras;
            parametros[10] = "@ControlPorHoras";
            parametros[11] = bControlPorHoras;
            parametros[12] = "@UltimaMod";
            parametros[13] = fecha;

            dbManager db = new dbManager();
            db.Conectar();

            object salida = db.EjecutarSP("VEHICULOS_INSERT", parametros);
            db.Desconectar();
            try
            {
                iRet = int.Parse(salida.ToString());
            }
            catch (Exception ex)
            {
                iRet = -10;
            }
            return iRet;
        }

        public static int modificar
            (string sMatricula, int idModelo, int idExplotacion, int iKilometros, int iHoras, bool bControlPorHoras, DateTime fecha)
        {
            int iRet = -1;

            object[] parametros = new object[14];
            parametros[0] = "@Matricula";
            parametros[1] = sMatricula;
            parametros[2] = "@IdModelo";
            parametros[3] = idModelo;
            parametros[4] = "@IdExplotacion";
            parametros[5] = idExplotacion;
            parametros[6] = "@Kilometros";
            parametros[7] = iKilometros;
            parametros[8] = "@Horas";
            parametros[9] = iHoras;
            parametros[10] = "@ControlPorHoras";
            parametros[11] = bControlPorHoras;
            parametros[12] = "@UltimaMod";
            parametros[13] = fecha;

            dbManager db = new dbManager();
            db.Conectar();

            object salida = db.EjecutarSP("VEHICULOS_UPDATE", parametros);
            db.Desconectar();
            try
            {
                iRet = int.Parse(salida.ToString());
            }
            catch (Exception ex)
            {
                iRet = -10;
            }
            return iRet;
        }

        public static int eliminar
            (string sMatricula)
        {
            int iRet = -1;

            object[] parametros = new object[2];
            parametros[0] = "@Matricula";
            parametros[1] = sMatricula;

            dbManager db = new dbManager();
            db.Conectar();

            object salida = db.EjecutarSP("VEHICULOS_DELETE", parametros);
            db.Desconectar();
            try
            {
                iRet = int.Parse(salida.ToString());
            }
            catch (Exception ex)
            {
                iRet = -10;
            }
            return iRet;
        }
        
    }
}
